import {observable, action} from 'mobx';
import moment from 'moment';
import {message} from 'antd';
import { WeaLocaleProvider,} from 'ecCom';

import * as Api from '../../apis/staffKanban';
const getLabel = WeaLocaleProvider.getLabel;
export default class StaffKanbanStore {
  @observable spinning = false;
  @observable hrmloading = false;
  @observable tabSpinning = false;
  @observable pageNum = 2;
  @observable dialogHeight = 0;
  @observable totalpage = 0;
  @observable mysubs = {};
  @observable attentionData = [];
  @observable selectKeyArr = [];
  @observable defaultkey = '';
  @observable defaultHrm = [];
  @observable selectHrmStr = [];
  @observable rightStatus = {
    timeType: 'month',
    date: moment().format('YYYY-MM-DD'),
    defBgTime: 0,//defBgTime开始时间的整数
    defEdTime: 24,//；defEdTime结束时间的整数
    defBgTimeStr: "00:00",//defBgTimeStr 开始时间的字符串；
    defEdTimestr: "23:59", //defEdTimestr结束时间的字符串
    zone_offset:8,
    weekstartday: 0,
  };

  @observable myboss= [];
  @observable subVisible = true;

  @action 
  setRightStatus = (params) => {
    Object.keys(params).forEach(key => {
      this.rightStatus[key] = params[key];
    });
  }
  @action 
  setState = (params={}) => {
    Object.keys(params).forEach(key => {
      this[key] = params[key];
    });
  }

  @action 
  getMySubs = (params, callback) => {
    this.tabSpinning = true;
    Api.getMySubs(params).then(res => {
      this.tabSpinning = false;
      this.mysubs = res.datas.rootManager;
      typeof(callback) == 'function' && callback(res.datas.rootManager.id)
    });
  }

  @action
  getCalendarBaseData = (params, callback) => {
    Api.getCalendarBaseData(params).then(res => {
      this.defaultkey = res.id;
      this.defaultHrm.push(res.name);
      this.selectHrmStr.push(res.name);
      this.setRightStatus({weekstartday: res.weekStartDay, });
      typeof(callback) == 'function' && callback()
    });
  }

  @action
  getAttentionData = (params, callback) => { // 获取关注者
    let param = {...params, fromWeaSelect: 1};
    this.hrmloading = true;
    Api.getAttentionData(param).then(res => {
      this.hrmloading = false;
      this.attentionData = res.data;

      this.totalpage = res.totalpage;
      typeof(callback) == 'function' && callback(res.data[0].id);
    });
  }

  @action
  addAttentionBrowser = (ids, callback) => { // 添加关注者
    let params = {touserid: ids};
    Api.addAttentionBrowser(params).then(res => {
      if(res.api_status) {
        typeof(callback) == 'function' && callback();
        message.success(getLabel(83551,'保存成功！'));
      }else{
        message.error(getLabel(84544,'保存失败！') );
      }
    });
  }
  
  @action 
  getAllManagerData = (params) => { // 上级
    Api.getAllManagerData(params).then(res => {
      this.myboss = res.data;
    });
  }

}